/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package auditenergetic;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;

/**
 * CONSUMUL DE ENERGIE PENTRU PREPARAREA APEI CALDE DE CONSUM
 * 
 */
public class CEPACC extends DefaultHandler{
    
    public double Q_ac; //necesarul de caldura pentru prepararea apei calde de consum livrata
    public double Q_acc;
    public double Q_acd;
    public double Ui;
    boolean T_acc = false;
    boolean da = false;
    boolean di = false;
    boolean Tm = false;
    boolean Tai = false;
    boolean Li = false;
    boolean T_ac = false ;
    boolean T_ar = false;

   // boolean a = false;
    boolean Nz = false;
    boolean z = false;

    public static String sT_ac;
    public static String sT_ar;
    public static String sT_acc;
    public static String s_da;
    public static String s_di;
    public static String s_Tm;
    public static String s_Tai;
    public static String s_Ui;
    public static String s_Li;

    public final double p = 983.2;
    public final double c = 4.183;
    public final double a = 50;
    public final double Nu = 62; //numarul de persoane
   
    public final double f1 = 1.3;
    public final double f2 = 1.1;
    public final double l_iz = 0.0462;
    public final double la = 1/0.33;
    public final double tH = 8760;

    @Override
    public void startElement(String nsURI, String strippedName,String tagName, Attributes attributes)
        throws SAXException
        {
            if (tagName.equalsIgnoreCase("T_ac"))
                T_ac = true;
            if (tagName.equalsIgnoreCase("T_ar"))
                T_ar = true;
            if (tagName.equalsIgnoreCase("T_acc"))
                T_acc = true;
            if(tagName.equalsIgnoreCase("da"))
                da = true;
             if (tagName.equalsIgnoreCase("di"))
                di = true;
            if (tagName.equalsIgnoreCase("Tm"))
                Tm = true;
            if (tagName.equalsIgnoreCase("Tai"))
                Tai = true;
           
            if(tagName.equalsIgnoreCase("Li"))
                Li = true;

        }
    @Override
    public void characters(char[] ch,int start,int length)throws SAXException
    {
        if(T_ac)
        {
            sT_ac = new String(ch,start,length);
           // System.out.println(sT_ac);
            T_ac = false;
        }
        if(T_ar)
        {
            sT_ar = new String(ch,start,length);
            //System.out.println(sT_ar);
            T_ar = false;
        }
        if(T_acc)
        {
            sT_acc = new String(ch,start,length);
           // System.out.println(sT_acc);
            T_acc = false;
        }
        if(da)
        {
            s_da = new String(ch,start,length);
            //System.out.println(s_da);
            da = false;
        }
        if(di)
        {
            s_di = new String(ch,start,length);
           // System.out.println(s_di);
            di = false;
        }
        if(Tm)
        {
            s_Tm = new String(ch,start,length);
           // System.out.println(s_Tm);
            Tm = false;
        }
        if(Tai)
        {
            s_Tai = new String(ch,start,length);
            //System.out.println(s_Tai);
            Tai = false;
        }
        
        if(Li)
        {
            s_Li = new String(ch,start,length);
           // System.out.println(s_Li);
            Li = false;
        }
    }
    public double ComputeV_ac()
    {
        return a*(Nu/1000);
    }

    public double ComputeQ_ac()
    {
        return  p * c * ComputeV_ac() * (Double.parseDouble(sT_ac) - Integer.parseInt(sT_ar));
    }
    public double ComputeV_acc()
    {
        return  ComputeV_ac() * f1 * f2 -ComputeV_ac();
    }
    public double Compute_Ui()
    {
        double c1 = 1/(2*l_iz);
        double c2 = Math.log(Double.parseDouble(s_da)/Double.parseDouble(s_di));
        double c3 = 1/(la*Double.parseDouble(s_da));
        Ui = Math.PI/(c1*c2+c3);
        return Ui;
    }
    public double ComputeQ_acd()
    {
        double prod = 1;
        double sum = 0;
        prod = Compute_Ui() * (Double.parseDouble(s_Tm) - Double.parseDouble(s_Tai)) *
                Double.parseDouble(s_Li) * tH;
        sum = sum + prod;
        Q_acd = sum;
        return Q_acd;
    }
    public double ComputeQ_acc()
    {
        double suma = 0.0;
        double prod = 1.0;
        
        prod = p * c * ComputeV_acc() * (Double.parseDouble(sT_acc) - Double.parseDouble(sT_ar));
        suma = suma + prod;
        Q_acc = suma;
        return Q_acc;
    }


    public double ComputeQ_acm()
    {
        return ComputeQ_ac() + ComputeQ_acc() + ComputeQ_acd();
        
    }


}
